/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.buzzwords.behaviors;

import com.buzzwords.exceptions.DuplicateEntryException;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author devinpartlow
 */
public class UserUUIDBehavior extends UserBehavior {

    @Override
    public List<Object> read(Object value) {
        String uuid;
        if (value instanceof String) {
            uuid = (String) value;
            if(uuid.isEmpty()) {
                throw new IllegalArgumentException("Search string cannot be empty");
            }
        } else {
            throw new IllegalArgumentException("Search value must be a String");
        }

        EntityManager em = emf.createEntityManager();
        Query query = em.createNamedQuery("User.findByUuid").setParameter("uuid", uuid);
        List<Object> users = query.getResultList();
        em.close();

        return users;
    }

}
